/**
 *
 * Copyright by Samuel Castro & Joaquim Fonseca, 2011
 * All Rights Reserved
 *
 * NOTES:
 * Please do not redistribute this plugin without my permission
 * Plugin made for private use only
 *
 */
package com.SySammy.sdMiningChallenge.Listeners;

import com.SySammy.sdMiningChallenge.challengeMethods;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;

public class sdMinningListener extends BlockListener {

    public static String mat;
    public static int qnt;
    private challengeMethods CM = new challengeMethods();

    @Override
    public void onBlockPlace(BlockPlaceEvent event) {
        if (event.getBlock().getType().equals(Material.COAL_ORE) || event.getBlock().getType().equals(Material.IRON_ORE) || event.getBlock().getType().equals(Material.LAPIS_ORE) || event.getBlock().getType().equals(Material.GOLD_ORE) || event.getBlock().getType().equals(Material.REDSTONE_ORE) || event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
            event.getPlayer().sendMessage(ChatColor.RED + "Sorry, ORE blocks can't be placed on this server.");
            event.setCancelled(true);
        }
        if (event.getBlock().getType().equals(Material.getMaterial(mat)) && challengeMethods.started == true && event.getPlayer() instanceof Player) {
            Player ply = (Player) event.getPlayer();
            ply.sendMessage(ChatColor.RED + "[MC]: You can't place the block you are looking for!!!");
            event.setCancelled(true);
        }
    }

    @Override
    public void onBlockBreak(BlockBreakEvent event) {
        Player ply = (Player) event.getPlayer();
        if (event.getBlock().getType().equals(Material.getMaterial(mat)) && challengeMethods.started == true) {
            challengeMethods.scores.put(ply.getName(), challengeMethods.scores.get(ply.getName()) + 1);
            ply.sendMessage(challengeMethods.scores.toString());
            if (challengeMethods.scores.get(ply.getName()) >= qnt) {
                challengeMethods.winner = ply;
                CM.GivePrize();
            }
        } else {
            return;
        }
    }
}
